package com.kingsoft.dc.khaos.plugin.core.utils;

import java.io.File;
import java.util.Map;

/**
 * 工具类.
 */
public class Utils extends Logging{
    private String KHAOS_CONF_DIR = "KHAOS_CONF_DIR";
    private String KHAOS_HOME = "KHAOS_HOME";
    /** Return the path of the default Ditto properties file. */
    public String getDefaultPropertiesFile(Map<String, String> env) {
        String confDir = null;
        String confFileName = null;
        if (env.containsKey(KHAOS_CONF_DIR)) {
            confDir = env.get(KHAOS_CONF_DIR);
            logWarning(KHAOS_CONF_DIR + "has not set");
        } else if (env.containsKey(KHAOS_HOME)) {
            confDir = env.get(KHAOS_HOME) + "/conf" ;
        }
        if (confDir == null) {
            logWarning(KHAOS_CONF_DIR + " and " + KHAOS_HOME + " has not set");
        } else {
            confFileName = confDir + "/khaos-defaults.conf";
            File confFile = new File(confFileName);
            if (!confFile.exists()) {
                logError(confFileName + " not exist");
                confFileName = null;
            }
        }
        return confFileName;
    }

    public static String[] formatMainArg(String[] args) {
        return args;
    }
}
